<?php
//App::uses('AppModel', 'Model');
App::uses('AppModel', 'Model', 'AuthComponent', 'Controller/Component');
/**
 * User Model
 *
 * @property Group $Group
 * @property User $User
 */
class User extends AppModel {

	
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'username';

	


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	
	
	public $actsAs = array('Acl' => array('type' => 'requester'));

    	public function parentNode() {
       		 if (!$this->id && empty($this->data)) {
       		     return null;
       		 }
       		 if (isset($this->data['User']['group_id'])) {
       		     $groupId = $this->data['User']['group_id'];
       		 } else {
       		     $groupId = $this->field('group_id');
       		 }
       		 if (!$groupId) {
       		     return null;
       		 } else {
       		     return array('Group' => array('id' => $groupId));
       		 }
    	}

/*	public function beforeSave($options = array()) {
       		$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        	return true;
    	}
*/
	public function bindNode($user) {
   		return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);
	}


}
